0% found this document useful (0 votes)
24 views8 pages

Message

Uploaded by

bnnrghq9hx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views8 pages

Message

Uploaded by

bnnrghq9hx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

#include <stdio.

h>
#include <stdlib.h>

void WinScreen()
{
printf("You won! Congratulations!\n\n");
}

void LoseScreen()
{
printf("You lose! Better luck next time!\n\n");
}

char PrintBoard(int x1, int y1, int x2, int y2, int x3, int y3, int x)
{
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if(i == 0 || i == 6 || i == 8)
{
printf("-");
}
else
{
if (j == 0 || j == 2 || j == 4 || j == 6 || j == 8)
{
printf("|");
}
else
{
if(x == j && 7 == i)
{
printf("P");
}
else if(x1 == j && y1 == i)
{
printf("X");
}
else if(x2 == j && y2 == i)
{
printf("X");
}
else if(x3 == j && y3 == i)
{
printf("X");
}
else
{
printf(" ");
}
}
}
}
printf("\n");
}
}

int main()
{
int movement = 0;
char ch;

int x = 1, score = 0, end = 0;


int x1 = 1, x2 = 3, x3 = 5;
int y1 = 1, y2 = 1, y3 = 1;

do{
int choice, validMove = 1;
PrintBoard(x1, y1, x2, y2, x3, y3, x);

printf("Score: %d\n", score);


printf("Actions:\n");
printf(" 1 - move left\n");
printf(" 2 - move right\n");
printf(" 3 - fire laser\n");

printf("Input action: ");


scanf("%d", &choice);
scanf("%c", &ch);

if(choice == 1)
{
if(x != 1)
{
x -= 2;
}
else
{
validMove = 0;
}
}
else if(choice == 2)
{
if(x != 7)
{
x += 2;
}
else
{
validMove = 0;
}
}
else if(choice == 3)
{
validMove = 1;
if(x1 == x) {
score += 10;
y1 = 1;
if(movement == 0 || movement == 1 || movement == 3){
int xMove = 1;
while((y2 == 1 && x2 == xMove) || (y3 == 1 && x3 == xMove)){
xMove += 2;
}
x1 = xMove;
}
else if(movement == 2){
int xMove = 3;
while((y2 == 1 && x2 == xMove) || (y3 == 1 && x3 == xMove)){
xMove += 2;
}
x1 = xMove;
}
}
if(x2 == x) {
score += 10;
y2 = 1;
if(movement == 0 || movement == 1 || movement == 3){
int xMove = 1;
while((y1 == 1 && x1 == xMove) || (y3 == 1 && x3 == xMove)){
xMove += 2;
}
x2 = xMove;
}
else if(movement == 2){
int xMove = 3;
while((y1 == 1 && x1 == xMove) || (y3 == 1 && x3 == xMove)){
xMove += 2;
}
x2 = xMove;
}
}
if(x3 == x) {
score += 10;
y3 = 1;
if(movement == 0 || movement == 1 || movement == 3){
int xMove = 1;
while((y1 == 1 && x1 == xMove) || (y2 == 1 && x2 == xMove)){
xMove += 2;
}
x3 = xMove;
}
else if(movement == 2){
int xMove = 3;
while((y1 == 1 && x1 == xMove) || (y2 == 1 && x2 == xMove)){
xMove += 2;
}
x3 = xMove;
}
}
}
else
{
validMove = 0;
}

if(validMove == 1)
{
if(movement == 0)
{
for (int i = 7; i > 0; i--)
{
if(x1 == i)
{
if(x1 != 7)
{
if(y1 == y2 || y1 == y3)
{
if(y1 == y2 && y1 == y3)
{
if(x1 + 2 != x2 && x1 + 2 != x3)
{
x1 += 2;
}
}
else if(y1 == y2 && x1 + 2 != x2)
{
x1 += 2;
}
else if(y1 == y3 && x1 + 2 != x3)
{
x1 += 2;
}
}
else
{
x1 += 2;
}
}
}
if(x2 == i)
{
if(x2 != 7)
{
if(y2 == y1 || y2 == y3)
{
if(y2 == y1 && y2 == y3)
{
if(x2 + 2 != x1 && x2 + 2 != x3)
{
x2 += 2;
}
}
else if(y2 == y1 && x2 + 2 != x1)
{
x2 += 2;
}
else if(y2 == y3 && x2 + 2 != x3)
{
x2 += 2;
}
}
else
{
x2 += 2;
}
}
}
if(x3 == i)
{
if(x3 != 7)
{
if(y3 == y1 || y3 == y2)
{
if(y3 == y1 && y3 == y2)
{
if(x3 + 2 != x1 && x3 + 2 != x2)
{
x3 += 2;
}
}
else if(y3 == y1 && x3 + 2 != x1)
{
x3 += 2;
}
else if(y3 == y2 && x3 + 2 != x2)
{
x3 += 2;
}
}
else
{
x3 += 2;
}
}
}
}
movement++;
}
else if(movement == 1 || movement == 3)
{
for (int i = 5; i > 0; i--)
{
if(y1 == i)
{
if(y1 == 5)
{
y1 += 2;
end = 1;

PrintBoard(x1, y1, x2, y2, x3, y3, x);


}
else
{
y1 += 1;
}
}
if(y2 == i)
{
if(y2 == 5)
{
y2 += 2;
end = 1;

PrintBoard(x1, y1, x2, y2, x3, y3, x);


}
else
{
y2 += 1;
}
}
if(y3 == i)
{
if(y3 == 5)
{
y3 += 2;
end = 1;

PrintBoard(x1, y1, x2, y2, x3, y3, x);


}
else
{
y3 += 1;
}
}
}

if(movement == 3)
{
movement = 0;
}
else
{
movement++;
}
}
else if(movement == 2)
{
for (int i = 0; i < 8; i++)
{
if(x1 == i)
{
if(x1 != 1)
{
if(y1 == y2 || y1 == y3)
{
if(y1 == y2 && y1 == y3)
{
if(x1 - 2 != x2 && x1 - 2 != x3)
{
x1 -= 2;
}
}
else if(y1 == y2 && x1 - 2 != x2)
{
x1 -= 2;
}
else if(y1 == y3 && x1 - 2 != x3)
{
x1 -= 2;
}
}
else
{
x1 -= 2;
}
}
}
if(x2 == i)
{
if(x2 != 1)
{
if(y2 == y1 || y2 == y3)
{
if(y2 == y1 && y2 == y3)
{
if(x2 - 2 != x1 && x2 - 2 != x3)
{
x2 -= 2;
}
}
else if(y2 == y1 && x2 - 2 != x1)
{
x2 -= 2;
}
else if(y2 == y3 && x2 - 2 != x3)
{
x2 -= 2;
}
}
else
{
x2 -= 2;
}
}
}

if(x3 == i)
{
if(x3 != 1)
{
if(y3 == y1 || y3 == y2)
{
if(y3 == y1 && y3 == y2)
{
if(x3 - 2 != x1 && x3 - 2 != x2)
{
x3 -= 2;
}
}
else if(y3 == y1 && x3 - 2 != x1)
{
x3 -= 2;
}
else if(y3 == y2 && x3 - 2 != x2)
{
x3 -= 2;
}
}
else
{
x3 -= 2;
}
}
}
}
movement++;
}
}
}while(score != 100 && end == 0);
if(score == 100)
{
WinScreen();
}
else if(end == 1)
{
LoseScreen();
}

return 0;
}

You might also like