write a MIPS assembly language program for a snake project using the c code under
I’m working on a c project and need an explanation and answer to help me learn.
write a MIPS assembly language program for a snake project using the c code under
a#include <conio.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int t, n, h = 20, wid = 20;
int done, achievement;
int w, q, foodw, foodq, status;
void enviroment()
{
done = 0;
w = h / 2;
q = wid / 2;
labe11:
foodw = rand() % 20;
if (foodw == 0)
goto label2;
label2:
foodq = rand() % 20;
if (foodq == 0)
goto label2;
achievement = 0;
}
void design()
{
system(“cls”);
for (t = 0; t < h; t++) {
for (n = 0; n < wid; n++) {
if (t == 0 || t == wid – 1
|| n == 0
|| n == h – 1) {
printf(“-“);
}
else {
if (t == w && n == q)
printf(“0”);
else if (t == foodw
&& n == foodq)
printf(“*”);
else
printf(” “);
}
}
printf(“n”);
}
printf(“achievemnt = %d”, achievement);
printf(“n”);
printf(“press X to quit the game”);
}
void play()
{
if (kbhit()) {
switch (getch()) {
case ‘a’:
status = 1;
break;
case ‘s’:
status = 2;
break;
case ‘d’:
status = 3;
break;
case ‘w’:
status = 4;
break;
case ‘x’:
done = 1;
break;
}
}
}
void logic()
{
sleep(0.01);
switch (status) {
case 1:
q–;
break;
case 2:
w++;
break;
case 3:
q++;
break;
case 4:
w–;
break;
default:
break;
}
if (w < 0 || w > h
|| q < 0 || q > wid)
done = 1;
if (w == foodw && q == foodq) {
label003:
foodw = rand() % 20;
if (foodw == 0)
goto label003;
label004:
foodq = rand() % 20;
if (foodq == 0)
goto label004;
achievement += 10;
}
}
void main()
{
int m, ph;
enviroment();
while (!done) {
design();
play();
logic();
}
}
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.
